package com.gxa.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.admin.mapper.UserMapper;
import com.gxa.admin.param.UserParam;
import com.gxa.admin.service.UserService;
import com.gxa.o2o.core.dto.ResultDTO;
import com.gxa.o2o.core.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    /**
     * 通过条件查询列表
     * @param param
     * @return
     */
    @Override
    public ResultDTO listByParam(UserParam param) {
        PageHelper.startPage(param.getPage(),param.getLimit());
        List<User> userList = userMapper.findByParam(param);
        PageInfo<User> userPageInfo = PageInfo.of(userList);
        return new ResultDTO(200,"查询成功",userPageInfo);
    }

    /**
     * 通过id查询
     * @param id
     * @return
     */
    @Override
    public ResultDTO findById(String id) {
        if (id == null || id.isEmpty() || Integer.valueOf(id) <= 0) {
            return new ResultDTO(1001,"id错误");
        }
        //查询
        User user = userMapper.selectByPrimaryKey(id);
        return new ResultDTO(200,"查询成功",user);
    }

    /**
     * 删除账号
     * @param id
     * @return
     */
    @Override
    public ResultDTO delete(String id) {


        return null;
    }

    @Override
    public ResultDTO updateStatus(String id) {
        return null;
    }


}
